import { defineConfig, loadEnv } from "vite";
import vue from "@vitejs/plugin-vue";
import path from "node:path";
import svgLoader from "vite-svg-loader";
import { viteMockServe } from "vite-plugin-mock";

export default defineConfig(({ mode }) => {
  const env = loadEnv(mode, process.cwd());
  return {
    plugins: [
      vue(),
      svgLoader(),
      viteMockServe({
        mockPath: "mock",
        enable: true,
      }),
    ],
    resolve: {
      alias: {
        "@": path.resolve(__dirname, "./src"),
      },
    },
    css: {
      preprocessorOptions: {
        scss: {
          additionalData: `@use "@/styles/variable.scss" as variable;`,
        },
      },
    },
    server: {
      proxy: {
        [env.VITE_BASE_API]: {
          target: env.VITE_BASE_API,
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/management/, ""),
        },
      },
    },
  };
});
